<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-input placeholder="请输入内容" v-model="inputvalue">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <el-table :data="orderList" style="width: 100%" border stripe>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.pay_status == '0'">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货">
          <template slot-scope="scope">
            {{ scope.row.is_send }}
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataformat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editInfo"></el-button>
            <el-button type="success" icon="el-icon-location-outline" size="mini" @click="process"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 修改地址面板 -->
    <el-dialog title="修改地址" :visible.sync="dialogVisible" width="50%" @close="addressclosed">
      <el-form :model="addressForm" :rules="addressRules" ref="ruleFormRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader v-model="addressForm.address1" :options="cityData" :props="{ expandTrigger: 'hover' }"> </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="物流进度" :visible.sync="dialogVisible1" width="50%">
      <!-- timeline 时间线 -->
      <el-timeline>
        <el-timeline-item v-for="(activity, index) in processData" :key="index" :timestamp="activity.time">
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data() {
    return {
      orderList: [],
      total: 0,
      //查询输入框里面的值
      inputvalue: '',
      dialogVisible: false,
      dialogVisible1: false,
      query: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      addressForm: {
        address1: [],
        address2: '',
      },
      addressRules: {
        address1: [{ required: true, message: '请输入省市区/县', trigger: 'blur' }],
        address2: [{ required: true, message: '请输入详细地址', trigger: 'blur' }],
      },
      cityData,
      processData: [],
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.query,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      this.$message.success('获取订单列表成功')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange(val) {
      this.query.pagesize = val
      this.getOrderList()
    },
    handleCurrentChange(val) {
      this.query.pagenum = val
      this.getOrderList()
    },
    editInfo() {
      this.dialogVisible = true
    },
    addressclosed() {
      this.$refs.ruleFormRef.resetFields()
    },
    async process() {
      const { data: res } = await this.$http.get('/kuaidi/75451494840566')

      if (res.meta.status !== 200) {
        return this.$message.error('获取物流进度失败！')
      }
      console.log(res)

      this.processData = res.data

      this.dialogVisible1 = true
      // console.log(this.processData)
      console.log(11)
    },
  },
}
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item(1).css';
.el-input {
  width: 400px;
}

.el-pagination {
  margin-top: 15px;
}

.el-cascader {
  width: 100%;
}
</style>